package com.zsl.controller.Admin;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.zsl.dao.UsersDao;
import com.zsl.service.UsersService;
import com.zsl.service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "GetUserManageTable",urlPatterns = "/get/user/manage/table")
public class GetUserManageTable extends HttpServlet {
    UsersService usersService=new UsersServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        Map<String, Object> res = new HashMap<>();

        try {
            res=usersService.getAllUser();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            res.put("total",0);
            res.put("rows",new JSONArray());
        }finally {
            PrintWriter out = response.getWriter();
            out.write(JSON.toJSONString(res));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
